<?php
/**
 * This file belongs to huakaili project
 *
 * @author jszhang
 */
	require_once ( LIB_DIR.'classes/Pager.php' );
	global $platformList;
	//TODO, sortby, right side, javascript part
	$supportedSortBy = array( "flower_count", "response_count", "review_date", "contribution" );
	
	$pageVars = array();
	$errmsg = GetMessageStack();
	
	$shopDao = GetShopDAO();
	$reviewDao = GetReviewDAO();
	
	//write to database
	if(isset($_GET['platid'])&&is_numeric($_GET['platid'])) 
	{
		$platid=intval($_GET['platid']);
		if($shopDao->GetShopPlatform($platid)==false)
		{
			edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
		}
	}
	else 
	{
		$platid=0;
	}

	$page = 1;
	if( isset ($_GET['p'])){
		$page = intval( $_GET['p']) == 0?1:intval( $_GET['p']);
	}
	$sortby = "review_date";
	if( isset( $_GET['sortby']) && in_array( $_GET['sortby'], $supportedSortBy) ){
		$sortby = edp_db_input( $_GET['sortby'] );
	}
	$pageVars['sortby'] = $sortby;
	$order = "desc";
	if( isset ( $_GET['order'] ) ){
		if( $_GET['order'] == "asc" )
			$order = "asc";
	}
	$pageVars['order'] = $order;

	$pageVars['reviews'] = $reviewDao->GetByPlatId( $platid, COMMENT_PER_PAGE, $page, $sortby, $order );

	$reviewCount = $reviewDao->GetReviewCountByPlatId( $platid );
	
	/*
	$currentURL = $_SERVER["REQUEST_URI"];
	$currentURL = preg_replace( '/p=[0-9]+/', "", $currentURL );
	*/
	$currentURL=edp_href_link(PAGENAME_REVIEW_SUMMARY, 'platid='.$platid.'&sortby='.$sortby.'&order='.$order);

	// prepare page bar of search result
	$pageObj = new Pager($currentURL, $reviewCount, COMMENT_PER_PAGE, $page, UP_RESULT_PAGE );
	$pageVars['pagebar'] = $pageObj->getBar();

?>
